<?php

defined('G_IN_SYSTEM') or exit('No permission resources.');
define('MEMBER', true);

System::load_sys_fun('user');

class base extends SystemAction
{
    protected $userinfo = null;

    public function __construct()
    {
        $this->db = System::load_sys_class('model');

        $uid = $_SESSION['user_id'];

        if (!$uid) {
            $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
            $is_weixin = strpos($agent, 'micromessenger') ? true : false ;
            if($is_weixin){
                redirect('/index.php?g=portal&m=Index&a=duobao&query_string='.$_SERVER['QUERY_STRING']);
            }
            $this->userinfo = false;
        }

        if (isset($uid)) {
            //$this->userinfo = $this->db->GetOne("SELECT * from `@#_member` where `uid` = '$uid'");
            $this->userinfo = $this->db->GetOne("SELECT * from yyy.yy_real_users where `id` = '$uid'");
        }

        if (!$this->userinfo) {
            $this->userinfo = false;
        } else {
            $money = $this->db->GetOne("SELECT money FROM yyy.yy_user_wallet where `real_user_id` = '$uid'");
            $this->userinfo['money'] = $money['money']/100;
        }

        /*$shell = md5($this->userinfo['id'].$this->userinfo['password'].$this->userinfo['mobile'].$this->userinfo['email']);

        if ($ushell != $shell) {
            $this->userinfo = false;
        }*/

        global $_cfg;

        $_cfg['userinfos'] = $this->userinfo;
    }

    protected function checkuser($uid, $ushell)
    {
        $uid = intval(_encrypt($uid, 'DECODE'));

        $ushell = _encrypt($ushell, 'DECODE');

        if (!$uid) {
            return false;
        }

        if ($ushell === null) {
            return false;
        }

        $this->userinfo = $this->db->GetOne("SELECT * from `@#_member` where `uid` = '$uid'");

        if (!$this->userinfo) {
            $this->userinfo = false;

            return false;
        }
        $shell = md5($this->userinfo['id'].$this->userinfo['password'].$this->userinfo['mobile'].$this->userinfo['email']);
        if ($ushell != $shell) {
            $this->userinfo = false;

            return false;
        } else {
            return true;
        }
    }

    public function get_user_info()
    {
        if ($this->userinfo) {
            return $this->userinfo;
        } else {
            return false;
        }
    }

    protected function HeaderLogin()
    {
        _message('你还未登录，无权限访问该页！', WEB_PATH.'/member/user/login');
    }
}
